//
//  ECDHomeViewCell.m
//  XTCloud
//
//  Created by QA on 16/9/20.
//  Copyright © 2016年 ShangHai HaoLei Software Technology Co., Ltd. All rights reserved.
//

#import "ECDHomeViewCell.h"
#import "NSDictionary+DataFormat.h"

#import "JZMTBtnView.h"
#import "ModuleAuthorityEntity+CoreDataClass.h"
#import "QueryMessageService.h"

#import "WebViewController.h"
#import "GEPushViewControllerHelper.h"

#import "ECDFileDirectoryController.h"

#define CellWidth SuperWidth/3
#define CellHeight SuperWidth/3

@interface ECDHomeViewCell ()

@property (nonatomic, strong) UIView *backView1;
@property (nonatomic, strong) UINavigationController *navigationController;

@end

@implementation ECDHomeViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self initView];
    }
    return self;
}

- (void)setNavigationController:(UINavigationController*)navigationController
{
    _navigationController = navigationController;
}

+ (NSInteger)getCellHeight
{
    return SuperWidth/3*2;
}

- (void)initView
{
    self.backView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SuperWidth, CellHeight*2)];
    [self addSubview:_backView1];
    
    NSArray *imageResouser = @[@"filesystem_grid_icon_zip",@"filesystem_grid_icon_music",
                               @"filesystem_grid_icon_movie",@"filesystem_grid_icon_photo",
                               @"filesystem_grid_icon_app",@"filesystem_icon_folder"];
    NSArray *titleString = @[@"文档",@"音频",@"视频",@"图片",@"其他",@"所有文件"];
    
    //创建6个
    NSInteger menuCount = 6;
    for (int i = 0; i < menuCount; i++) {
        //是否可以点击
        CGRect frame = CGRectMake((i%3)*CellWidth, CellHeight*(i/3), CellWidth, CellHeight);
        UIView *itemView = [[UIView alloc] initWithFrame:frame];
        itemView.tag = i;
        [_backView1 addSubview:itemView];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(OnTapBtnView:)];
        [itemView addGestureRecognizer:tap];
        
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(frame.size.width/2-25, frame.size.height/2 - 25 - 20, 54, 54)];
        imageView.contentMode = UIViewContentModeRedraw;
        imageView.image = [UIImage imageNamed:imageResouser[i]];
        [itemView addSubview:imageView];
        
        UILabel *titleLable = [[UILabel alloc] initWithFrame:CGRectMake(0, imageView.frame.origin.y+50+10, frame.size.width, 20)];
        titleLable.text = titleString[i];
        titleLable.textAlignment = NSTextAlignmentCenter;
        titleLable.font = [UIFont systemFontOfSize:15];
        titleLable.textColor = [UIColorDispose colorWithHexString:@"#111111"];
        [itemView addSubview:titleLable];
    }
    
    //绘制分割线
    for (int i = 1; i < 3; i++){
        NSInteger heightRow = menuCount/3 + (menuCount%3>0 ? 1 : 0);
        
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(i*CellWidth, 0, 0.5, CellHeight*heightRow)];
        lineView.backgroundColor = [UIColor colorWithRed:221/255.0 green:221/255.0 blue:221/255.0 alpha:0.8];
        [_backView1 addSubview:lineView];
    }
    
    //绘制分割线
    for (int i = 1; i < menuCount/3; i++){
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, i*CellWidth, SuperWidth, 0.5)];
        lineView.backgroundColor = [UIColor colorWithRed:221/255.0 green:221/255.0 blue:221/255.0 alpha:0.8];
        [_backView1 addSubview:lineView];
    }
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
}

-(void)OnTapBtnView:(UITapGestureRecognizer *)sender
{
    NSLog(@"tag:%ld",sender.view.tag);
    
    //selType：1表示查询所有数据，val传递文件夹ID（顶层val默认为-1）
    //selType：2表示查询分类数据, val文件类型：0文档 1图片 2视频 3音频 10其他
    NSMutableDictionary *mDictionary = [NSMutableDictionary dictionary];
    if(sender.view.tag == 0){
        [mDictionary setObject:@"文档" forKey:@"title"];
        [mDictionary setObject:@2 forKey:@"selType"];
        [mDictionary setObject:@0 forKey:@"val"];
        
    } else if(sender.view.tag == 1){
        [mDictionary setObject:@"音频" forKey:@"title"];
        [mDictionary setObject:@2 forKey:@"selType"];
        [mDictionary setObject:@3 forKey:@"val"];
        
    } else if(sender.view.tag == 2){
        [mDictionary setObject:@"视频" forKey:@"title"];
        [mDictionary setObject:@2 forKey:@"selType"];
        [mDictionary setObject:@2 forKey:@"val"];
        
    } else if(sender.view.tag == 3){
        [mDictionary setObject:@"图片" forKey:@"title"];
        [mDictionary setObject:@2 forKey:@"selType"];
        [mDictionary setObject:@1 forKey:@"val"];
        
    } else if(sender.view.tag == 4){
        [mDictionary setObject:@"其他" forKey:@"title"];
        [mDictionary setObject:@2 forKey:@"selType"];
        [mDictionary setObject:@10 forKey:@"val"];
        
    } else if(sender.view.tag == 5){
        [mDictionary setObject:@"所有文件" forKey:@"title"];
        [mDictionary setObject:@1 forKey:@"selType"];
        [mDictionary setObject:@-1 forKey:@"val"];
    }
    
    ECDFileDirectoryController *view = [[ECDFileDirectoryController alloc] initWithValue:mDictionary];
    [self.navigationController pushViewController:view animated:YES];
}

@end
